<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of project
 *
 * @author truongkx
 */
class news extends BACKEND_Controller{
    //put your code here
    function __construct() {
        parent::__construct('news','news_');
        $this->load->model('cp/news_model');
        $this->load->model('cp/category_model');
    }
    public function binding($type=null){
        $data = $this->news_model->binding($type);
        $R=$data;
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
    function tokeninput(){
        $q=$this->input->get_post('q');
        $data = $this->news_model->search($q);
        $R=$data;
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
    function index(){
        echo $c=$this->load->view('cms/cp/03_news/viewport',$this->assigns,true);
    }
    
    function editpanel(){
        $data = $this->category_model->get_by_type();
        $data =$this->category_model->buildTreeArray($data);
        $this->assigns->cates=$data;
        $Id=(int)$this->input->post('Id');
        if($Id>0){
            $this->assigns->item=$this->news_model->onGet($Id);
            if(!empty($this->assigns->item))
                $relatedids=  explode (',', $this->assigns->item->Related);
                $R["related"]=$this->news_model->getIn($relatedids);
        }
        $c=$this->load->view('cms/cp/03_news/editpanel',$this->assigns,true);
        $R["result"] = 1;
        $R["message"]='SUCCESS !';
        $R["htmlreponse"]=$c;
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
}
